//
//  UIButton+Extension.swift
//  ZHBlog_swift
//
//  Created by ZHLEEBlander on 15/10/14.
//  Copyright © 2015年 ZHLEEBlander. All rights reserved.
//

import Foundation
import UIKit

extension UIButton{

    class func button(title title:String="",titleFontFloat:CGFloat = 0,titleColor:UIColor = UIColor.darkGrayColor(),image: String="",bgImage:String="",selectedImage:String="",target: AnyObject?, action: Selector)->UIButton {
        
        let Btn = UIButton()
        
        Btn.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        if title.characters.count > 0 {
            Btn.setTitle(title, forState: UIControlState.Normal)
        }
        if image.characters.count > 0{
        
            Btn.setImage(UIImage(named: image), forState: UIControlState.Normal)
            Btn.setImage(UIImage(named: "\(image)_highlighted"), forState: UIControlState.Highlighted)
        }
        Btn.setTitleColor(titleColor, forState: UIControlState.Normal)
        if bgImage.characters.count > 0{
        
            Btn.setBackgroundImage(UIImage(named: bgImage), forState: UIControlState.Normal)
            Btn.setBackgroundImage(UIImage(named: "\(bgImage)_highlighted"), forState: UIControlState.Highlighted)
        }
        if selectedImage.characters.count > 0 {
            Btn.setImage(UIImage(named: selectedImage), forState: UIControlState.Selected)
        }
        if titleFontFloat != 0{
        
            Btn.titleLabel?.font = UIFont.systemFontOfSize(titleFontFloat)
        }
        Btn.sizeToFit()
        return Btn
    }
}
